package cn.com.zero.common.message.config;

import cn.com.zero.common.message.adapter.ISendMessage;
import cn.com.zero.common.message.adapter.test.SendMessageTest;
import cn.com.zero.common.message.config.properties.MessageProperties;
import cn.com.zero.common.message.enums.MessageChannelEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiongxj
 * @version 1.0.0
 * @Description 消息的配置类
 * @createTime 2023/2/24 15:23
 */
@Configuration
public class MessageConfig {

    private MessageProperties messageProperties;

    /**
     * 创建发送消息的适配器
     *
     * @return 适配器
     */
    @Bean
    public ISendMessage createMessageAdapter() {
        MessageChannelEnum channelEnum = MessageChannelEnum.get(messageProperties.getChannel());
        if (null == channelEnum) {
            return new SendMessageTest();
        }
        switch (channelEnum) {
            case TEST:
                return new SendMessageTest();
            case JTD:
                return new SendMessageTest();
            case ALI:
                return new SendMessageTest();
            case EMAY:
                return new SendMessageTest();
            default:
                return new SendMessageTest();
        }
    }

    @Autowired
    public void setMessageProperties(MessageProperties messageProperties) {
        this.messageProperties = messageProperties;
    }
}
